package logic

import (
	"context"
	"doc-manage/models/mysql"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
)

type DoctorUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorUpdateLogic {
	return &DoctorUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改
func (l *DoctorUpdateLogic) DoctorUpdate(in *docrpc.DoctorUpdateRequest) (*docrpc.DoctorUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	doctor = mysql.Doctor{
		Model:         gorm.Model{},
		DoctorName:    in.DoctorName,
		DoctorAddress: in.DoctorAddress,
		DoctorDetail:  in.DoctorDetail,
	}
	err := doctor.DoctorUpdate(mysql.DB, in.DoctorId)
	if err != nil {
		return nil, err
	}
	return &docrpc.DoctorUpdateResponse{
		DoctorId:      in.DoctorId,
		DoctorName:    in.DoctorName,
		DoctorAddress: in.DoctorAddress,
		DoctorDetail:  in.DoctorDetail,
	}, nil
}
